#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main()
{
    printf("testexec ...begin\n");
    
    pid_t id = fork();
    if (id == 0)
    {
        putenv("hhhhhHHHH=12123");
        char* const argv[] = 
        {
            (char*)"myprama",
            NULL
        };
        char* const envp[] = 
        {
            (char*)"Hell=111",
            (char*)"hjsidai=123434",
            NULL
        };
        //char* const argv[] = 
        //{
        //    (char*)"ls",
        //    (char*)"-a",
        //    (char*)"-l",
        //    (char*)"--color",
        //    NULL 
        //};
        //child
        extern char** environ;
        printf("child pid:%d\n", getpid());
        sleep(2);
        execvpe("./myprama", argv, environ);
        //execvpe("./myprama", argv, envp);
        //execl("/usr/bin/python3", "python3", "test.py", NULL);
        //execl("./myprama", "myprama", NULL);
        //execl("/usr/bin/ls", "ls", "-l", "-a", NULL);
        //execvp("ls", argv);
        //execvpe("myprama", NULL, NULL);
        exit(1);
    }
    //father
    int status = 0;
    pid_t rid = waitpid(id, &status, 0);
    if (rid > 0)
    {
        printf("father wait success, child exit code:%d\n",WEXITSTATUS(status));
    }

    printf("testexec ...end\n");

    return 0;
}
